package com.yra.controller.manager;

import com.yra.domain.MallUser;
import com.yra.service.MallUserService;
import com.yra.util.PageQueryUtil;
import com.yra.util.Result;
import com.yra.util.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author: yrq
 * @Date: Create in 11:02 2019/12/12
 */
@Controller
@RequestMapping("manager")
public class MallUserController {
    @Autowired
    private MallUserService mallUserService;

    @RequestMapping("/userPage")
    public ModelAndView goToUser(HttpServletRequest request){
        ModelAndView mv = new ModelAndView("/admin/newbee_mall_user");
        request.setAttribute("path", "users");
        return mv;
    }

    @RequestMapping(value = "/user/list")
    public ResponseEntity<Result> userList(@RequestParam Map<String ,Object> params){
        System.out.println("进入");
        PageQueryUtil pageQueryUtil = new PageQueryUtil(params);
        return ResponseEntity.status(HttpStatus.OK).body(ResultGenerator.genSuccessResult(mallUserService.mallUserListPage(pageQueryUtil)));
    }

    @RequestMapping(value = "/user/lock/{lockStatus}",method = RequestMethod.POST)
    public ResponseEntity<Boolean> updateLockStatus(@PathVariable("lockStatus") int lockStatus, @RequestBody int[] ids){

        return ResponseEntity.status(HttpStatus.OK).body(mallUserService.updateLockStatusByIds(lockStatus,ids));
    }

}
